
#if !defined(AFX_CGAITANALY_H__2012__INCLUDED_)
#define AFX_CGAITANALY_H__2012__INCLUDED_

#include "../Bluetooth/CWAManager.h"

#define			GAIT_POINT_ARRAY_SIZE			200
#define			GAIT_NUMBER_RANGE				200
#define			GAIT_X_SCALE_NUM				12
#define			GAIT_Y_SCALE_NUM				10
#define			MARGIN_RATIO					0.1

//  for indicator on the top of gait
#define			TOP_INDICATOR_BLOCK_WIDTH		0.05
#define			TOP_INDICATOR_INDI_MARGIN		0.02

class CGaitAnaly
{
public:
	CGaitAnaly();
	CGaitAnaly(CWnd* pDrawCtrl, int nWAIndex);
	~CGaitAnaly();

	BOOL				InitGait(CDC* pDC, CRect rectRange, DWORD aGaitArray[], int nStartPosInArray);
	BOOL				BeginDrawPrintGaitGraph(int nDestPosX, int nDestPosY);
	BOOL				DrawGaitCurve(DWORD aGaitArray[], int nStartPosInArray, int nDestPosX, int nDestPosY);
	BOOL				EndDrawPrintGaitGraph();

	BOOL				SetGaitPara(WA_BASIC_PARA* pBasicPara);
	WA_BASIC_PARA		GetGaitPara(){return m_BasicPara;}
	BOOL				StartDraw();
	BOOL				StopDraw();
	void				SetLineWidthMul(int nMul){m_nLineWidthMul = nMul;}

	void				PauseDraw(BOOL bPause){m_bGaitPause = bPause;}
	BOOL				IsDrawPaused(){return m_bGaitPause;}

	BOOL				SnapGait(DWORD dwMRNCode, int nDiagSN);
	BOOL				GetGaitSnap(DWORD aGaitArray[], int* pnArrayStartPos, DWORD* pnStiOpen, DWORD* pnStiClose);

	static BOOL			ReadGaitFromTable(DWORD dwMRNCode, int nDiagSN, CString strDate, DWORD dwGaitPoints[], int* pnStartPos, int* pnTriggerOpen, int* pnTriggerClose, CString* pstrDevID, CString* pstrDevAddress);
	static BOOL			ShowStaticGaitSnap(CWnd* pCtrl, int nDiagSN);
	static BOOL			HasSdiagSnapGait(DWORD dwMRNCode, int nDiagSN);

	static BOOL			ShowGaitInCtrl(CWnd* pCtrl, DWORD adwGaitPoints[], int nStartPos, DWORD dwStiOpen, DWORD dwStiClose, CString strDevID, CString strDevAddress);
	void				SetDevID(CString strDevID){m_strDevID = strDevID;}
	void				SetWAColor(COLORREF crWA){m_crWAColor = crWA;}
	void				SetCommVer(DWORD dwCommver){m_dwCommVer = dwCommver;}

private:
	static UINT	WINAPI	DrawGaitThread(LPVOID lpParam);
	BOOL				DrawGaitGraph(int nDestPosX = 0, int nDestPosY = 0);
	BOOL				DrawStopGraph();

	BOOL				BeginDraw(BOOL bDrawInCtrl = TRUE);
	BOOL				EndDraw(BOOL bDrawInCtrl = TRUE);

	void				RefreshStiOpenCloseValue(double dPixelNumPerDataX, double dPixelNumPerDataY, double dLenAxisX, double dLenAxisY);

private:
	WA_BASIC_PARA		m_BasicPara;
	CWnd*				m_pDrawCtrl;
	HANDLE				m_hDrawThread;
	int					m_nDevIndex;
	CString				m_strDevID;
	DWORD				m_dwCommVer;
	volatile BOOL		m_bNotifyStop;

	DWORD				m_aGaitPoints[GAIT_POINT_ARRAY_SIZE];
	int					m_nArrayPos;

	CDC*				m_pDC;
	CDC					m_MemDC;

	CBitmap*			m_pOldBitmap;
	CBitmap				m_MemBitmap;

	CRect				m_rectCtrl;
	CPoint				m_ptZero;

	CBrush				m_brushWhite;
	CBrush				m_brushWAColor;
	CBrush				m_brushRed;
	CBrush				m_brushBlue;
	CBrush				m_brushBlack;

	CPen				m_pen1Black;
	CPen				m_pen2Black;
	CPen				m_pen3Black;

	CPen				m_penGuidline;
	CPen				m_penRed;
	CPen				m_penBlue;

	COLORREF			m_crWAColor;
	BOOL				m_bGaitPause;

	int					m_nLineWidthMul;
};



#endif//AFX_CGAITANALY_H__2012__INCLUDED_
